﻿using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using BLL.Services.Authors;
using Web.Infrastructure.Models;

namespace Web.Areas.Admin.Models.Authors
{
    public class AuthorCreateModel : BaseModel
    {
        public AuthorCreateModel(Author author)
        {
            ToModel(author, this);
        }

        public AuthorCreateModel()
        {
        }

        [Display(Name = "First name")]
        [StringLength(256)]
        [Required]
        [Remote("Validate", "Authors", "Admin", AdditionalFields = "LastName,MiddleName", ErrorMessage = "Author with the same first name, last name and middle name already exists.")]
        public string FirstName { get; set; }

        [Display(Name = "Last name")]
        [StringLength(256)]
        [Required]
        [Remote("Validate", "Authors", "Admin", AdditionalFields = "FirstName,MiddleName", ErrorMessage = "Author with the same first name, last name and middle name already exists.")]
        public string LastName { get; set; }

        [Display(Name = "Middle name")]
        [StringLength(256)]
        [Remote("Validate", "Authors", "Admin", AdditionalFields = "FirstName,LastName", ErrorMessage = "Author with the same first name, last name and middle name already exists.")]
        public string MiddleName { get; set; }

        public static explicit operator Author(AuthorCreateModel model)
        {
            var author = new Author();
            ToEntity(model, author);
            return author;
        }
    }
}